/*
 * @(#)SAXNeihantuXml.java		       Project:Tools
 * Date:2012-4-11
 *
 * Copyright (c) 2011 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sinaapp.msdxblog.tools.xml.neihantu;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;


/**
 * @author Geek_Soledad (66704238@51uc.com)
 * @param <T>
 */
public class SAXNeihantuXml {
	private static final String ATTR_NAME = NeihantuXml.ATTR_NAME;
	private String mPath;
	private Map<String, String> maps = new HashMap<String, String>();
	public SAXNeihantuXml(String path) {
		mPath = path;
		saxXml();
	}
	
	/**
	 * 解析XML
	 */
	public void saxXml() {
		File file = new File(mPath);
		SAXBuilder builder = new SAXBuilder();
		try {
			Document document = builder.build(file);
			Element element = document.getRootElement();
			@SuppressWarnings("unchecked")
			List<Element> elements = element.getChildren();
			for (Element e : elements) {
				maps.put(e.getAttributeValue(ATTR_NAME), e.getText());
			}
			System.out.println(maps.get("p1"));
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main (String[] args) {
		new SAXNeihantuXml("C:/Users/msdx/Desktop/pictures/tips.xml");
	}

	public Map<String, String> getMaps() {
		return maps;
	}
}
